package com.dam.monngonmoingay;

//import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Filter;
import android.widget.ImageView;
import android.widget.TextView;

public class MonAnAdapter extends ArrayAdapter<MonAn> {
	//private static String TAG = "MonAnAdapter";

	private final List<MonAn> list;
	private final Activity context;
	public ImageLoader imageLoader;
	
	
	public MonAnAdapter(Activity context, List<MonAn> list) {
		super(context, R.layout.image_text_layout, list);
		this.context = context;
		this.list = list;
		imageLoader = new ImageLoader(context.getApplicationContext());
	}
	
	public static class ViewHolder {
		protected TextView textViewTitle;
		protected TextView textViewDesc;
		protected ImageView imageViewMonAn;

		
		protected long id;
		protected String image;
		protected String title;
		protected String material;
		protected String description;
		protected String content;
		protected String tips;
		protected String video;
		protected int like;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View view = null;
		if (convertView == null) {
			LayoutInflater inflator = context.getLayoutInflater();
			view = inflator.inflate(R.layout.image_text_layout, null);
			final ViewHolder viewHolder = new ViewHolder();

			viewHolder.textViewTitle = (TextView)view.findViewById(R.id.textViewTitle);	
			viewHolder.textViewDesc  = (TextView)view.findViewById(R.id.textViewDesc);	
			viewHolder.imageViewMonAn = (ImageView)view.findViewById(R.id.monAnImageView);
			view.setTag(viewHolder);
		} else {
			view = convertView;
		}
		
		ViewHolder holder = (ViewHolder)view.getTag();
		holder.textViewTitle.setText(list.get(position).getTitle());
		holder.textViewDesc.setText(list.get(position).getDesc());
		holder.id = list.get(position).getMonan_detail_id();
		holder.description = list.get(position).getDesc();
		holder.material = list.get(position).getMaterials();
		holder.content = list.get(position).getContent();
		holder.image = list.get(position).getPath_image();
		holder.title = list.get(position).getTitle();
		holder.tips = list.get(position).getTips();
		holder.video = list.get(position).getPath_video();
		holder.like = list.get(position).getLike();
		imageLoader.DisplayImage(list.get(position).getPath_image(), holder.imageViewMonAn);
		return view;
		
	
	}
	

	@Override
	public Filter getFilter() {
		return super.getFilter();
	}	
	
}
